<?php

namespace backend\controllers;

use yii\helpers\Url;
use yii\web\Controller;

class AdminController extends Controller
{





    /**
     * @param $content
     * @param string $url
     * @param string $title
     * @return string
     * 弹窗提示
     */
    public function dialog($content,$type="warning",$url='',$title='温馨提示')
    {
//        if(empty($url)){
//            $url = \Yii::$app->request->absoluteUrl;
//        }

        $order = array("\r\n", "\n", "\r");
        $content = str_replace($order, '', $content);
        return $this->render('@app/views/common/dialog',[
            'title'=>$title,
            'content'=>$content,
            'url'=>$url,
            'type' => $type
        ]);
    }


    /**
     * @param $content
     * @param $time
     * @param string $url
     * @param string $title
     * @return string
     * 定时弹窗
     */
    public function timeAlert($content,$url='',$time=2000,$title='温馨提示')
    {
//        if(empty($url)){
//            $url = \Yii::$app->request->absoluteUrl;
//        }
        $order = array("\r\n", "\n", "\r");
        $content = str_replace($order, '', $content);
        return $this->render('@app/views/common/timealert',[
            'content'=>$content,
            'title'=>$title,
            'url'=>$url,
            'time' => $time,
        ]);
    }

    /**
     * @param $model
     * @return bool
     * 校验错误
     */
    public function checkError($model)
    {
        foreach ($model->getErrors() as $key => $row)
        {
            return $row[0];
        }
        return true;
    }






    /**
     * 通用成功跳转
     * @param unknown $url 成功后跳转的URL
     * @param number $sec 自动跳转秒数
     * @return Ambigous <string, string>
     */
//    public function success($url= [] ,$sec = 3){
//        $url= empty($url)? ['/admin/main']: $url;
//        $url= \yii\helpers\Url::toRoute($url);
//        return $this->renderPartial('@app/views/common/msg',['gotoUrl'=>$url,'sec'=>$sec]);
//    }

    /**
     * 通用错误跳转
     * @param string $msg 错误提示信息
     * @param number $sec
     * @return Ambigous <string, string>
     */
//    public function error($msg= '',$sec = 3){
//        return $this->renderPartial('@app/views/common/msg',['errorMessage'=>$msg,'sec'=>$sec]);
//    }




}




